package com.maiworld.seller.controller;

import java.util.List;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.maiworld.pojo.TbNewtable;
import com.maiworld.seller.service.NewtableService;

import entity.PageResult;
import entity.Result;

@RestController
@RequestMapping("/newt")
public class NewtableController {
	
	@Reference
	private NewtableService newtableService;
	
	@RequestMapping("/findAll")
	public List<TbNewtable> findAll(){
		return newtableService.findAll();
	}
	
	@RequestMapping("/findPage")
	public PageResult findPage(int page, int rows){
		return newtableService.findPage(page, rows);
	}
	
	@RequestMapping("/add")
	public Result add(@RequestBody TbNewtable newtable){
		try{
			newtableService.add(newtable);
			return new Result(true, "增加成功");
		}catch(Exception e ){
			e.printStackTrace();
			return new Result(false, "增加失败");
		}
	}

	@RequestMapping("/update")
	public Result update(@RequestBody TbNewtable newtable){
		try{
			newtableService.update(newtable);
			return new Result(true, "修改成功");
			
		}catch(Exception e){
			e.printStackTrace();
			return new Result(false, "修改失败");
		}
	}
	
	@RequestMapping("/findOne")
	public TbNewtable findOne( Long id){
		return newtableService.findOne(id);
	}
	
	@RequestMapping("/delete")
	public Result delete(Long[] ids){
		try{
			newtableService.delete(ids);
			return new Result(true, "删除成功");
		}catch(Exception e ){
			e.printStackTrace();
			return new Result(false, "删除失败");
		}
	}
	
	@RequestMapping("/search")	
	public PageResult search(@RequestBody TbNewtable newtable ,int page, int rows){
		return newtableService.findPageNewtable(newtable, page, rows);
	}
	
}
